//
//  String+Extension.swift
//  日期类
//
//  Created by JJ on 15/9/20.
//  Copyright © 2015年 JJ. All rights reserved.
//

import Foundation

extension String{

    func href()->(link:String,text:String)?{
        
        let pattern="<a href=\"(.*?)\" .*?>(.*?)</a>"
        let regex=try! NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
        
        guard let result = regex.firstMatchInString(self, options:[], range: NSRange(location: 0, length: self.characters.count)) else{
            
            return nil
        }
        
        let link = (self as NSString).substringWithRange(result.rangeAtIndex(1))
        let text = (self as NSString).substringWithRange(result.rangeAtIndex(2))
        
        return (link,text)
    }
    
}